Imports System.Data
Imports System.Data.SqlClient
Imports DevExpress.XtraEditors.Controls
Imports System.IO
Imports DevExpress.XtraExport
Imports DevExpress.XtraGrid.Export


Public Class TuitionFeeStatus

    Private Filename As String = "C:\Program Files\Common Files\MemberSystem\TuitionFeeStatus.xml"

    Private Sub mnuSaveLayout_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuSaveLayout.Click
        Me.GridControl1.MainView.SaveLayoutToXml(Filename)
    End Sub

    Private Sub mnuLoadDefault_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuLoadDefault.Click
        Dim File, Folder, FileCollection
        'Dim fso As New Scripting.FileSystemObject

        If MsgBox("Are You Sure Want to Load Default Layout!", MsgBoxStyle.OkCancel) = MsgBoxResult.Ok Then

            If IO.File.Exists(Filename) Then
                IO.File.Delete(Filename)
            End If

            MsgBox("Please Reload the Page as Default Layout Loaded", MsgBoxStyle.Information)
            Me.Close()

        End If

    End Sub

    Private Sub GridControl1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles GridControl1.MouseDown
        If e.Button = MouseButtons.Right Then
            Me.ContextMenu = ContextMenu1
            Exit Sub
        End If
    End Sub


    Private Sub TuitionFeeStatus_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        LoadIcon(Me)
        loadLayout(Me.GridControl1, Filename)

        RefreshGrid()

    End Sub

    Private Sub RefreshGrid()

        Dim str As String
        str = "SELECT * FROM Fee_View"
        Dim cmd As New SqlCommand(str, gCnnPCE)
        Dim ds As New DataSet
        Dim da As New SqlDataAdapter(cmd)
        da.Fill(ds, "Records")
        Me.GridControl1.DataSource = ds.Tables(0)

        Me.lblMemberID.DataBindings.Clear()
        lblMemberID.DataBindings.Add(New Binding("Text", ds.Tables("Records"), "MemberID", True))

        Me.lblRecordCode.DataBindings.Clear()
        lblRecordCode.DataBindings.Add(New Binding("Text", ds.Tables("Records"), "Code", True))

        Me.lblRecordID.DataBindings.Clear()
        lblRecordID.DataBindings.Add(New Binding("Text", ds.Tables("Records"), "ID", True))




    End Sub

    Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
        Me.Close()
    End Sub

    Private Sub btnExport_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExport.Click
        Dim saveDialog As New SaveFileDialog
        saveDialog.Title = "Export To "
        saveDialog.Filter = "Microsoft Excel|*.xls|HTML Documents|*html|Text Files|*.txt|XML Document|*.xml"
        If saveDialog.ShowDialog() = Windows.Forms.DialogResult.OK Then
            Try
                Select Case saveDialog.FilterIndex
                    Case 1
                        Call ExportTo(New ExportXlsProvider(saveDialog.FileName), GridView1)
                    Case 2
                        Call ExportTo(New ExportHtmlProvider(saveDialog.FileName), GridView1)
                    Case 3
                        Call ExportTo(New ExportTxtProvider(saveDialog.FileName), GridView1)
                    Case 4
                        Call ExportTo(New ExportXmlProvider(saveDialog.FileName), GridView1)
                End Select
                MsgBox("Successfully Retrive to " & saveDialog.FileName & ".", MsgBoxStyle.Information)
            Catch ex As Exception
                MsgBox("Fail To Retrive : " & ex.Message, MsgBoxStyle.Information)
            End Try

        End If
    End Sub

    Private Sub ExportTo(ByVal provider As DevExpress.XtraExport.IExportProvider, ByVal grid As DevExpress.XtraGrid.Views.Grid.GridView)
        Dim link As BaseExportLink = grid.CreateExportLink(provider)
        CType(link, GridViewExportLink).ExpandAll = False
        link.ExportTo(True)
    End Sub

    Private Sub btnReport_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReport.Click
        Dim frm As New Report_FeeReport
        frm.ShowDialog()

    End Sub

    Private Sub btnReceipt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReceipt.Click
        Dim frm As New Report_Receipt_Tution
        frm.MemberID = lblMemberID.Text
        frm.Code = Me.lblRecordCode.Text
        frm.ShowDialog()
    End Sub
End Class